package com.demo1.listener;

import org.activiti.engine.delegate.DelegateExecution;
import org.activiti.engine.delegate.DelegateTask;
import org.activiti.engine.delegate.ExecutionListener;
import org.activiti.engine.delegate.TaskListener;
import org.activiti.engine.impl.el.FixedValue;
import org.apache.commons.io.FileUtils;

import java.io.File;
import java.io.IOException;
import java.io.Serializable;


public class Deme1ProcessExecutionListener implements ExecutionListener, TaskListener, Serializable {
    private File logFile=new File("E:/tmp/activity.txt");
    private FixedValue msg;

    @Override
    public void notify(DelegateExecution delegateExecution) {
//        往文件追加日志
        try {
            FileUtils.writeStringToFile(logFile, msg.getExpressionText() + "\n", true);
        } catch (IOException e) {
            e.printStackTrace();
        }
        System.out.println(
                "\u001B[32m" + msg.getExpressionText() + "\u001B[0m"
        );
    }

    @Override
    public void notify(DelegateTask delegateTask) {
        try {
            FileUtils.writeStringToFile(logFile, msg.getExpressionText() + "\n", true);

        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        System.out.println(
                "\u001B[32m" + msg.getExpressionText() + "\u001B[0m"
        );
    }
}
